package httpclient

import (
	"fmt"
	"strconv"
	"strings"
)

// processPriceData 处理请求返回的价格数据
func processPriceData(result KlineResult, apiSymbol string) (map[string]string, error) {
	if result.Status != "ok" || len(result.Data) == 0 {
		return nil, nil
	}
	priceData := result.Data[0]
	priceArr := make(map[string]string)
	priceArr["open"] = strconv.FormatFloat(priceData.Open, 'f', -1, 64)
	priceArr["close"] = strconv.FormatFloat(priceData.Close, 'f', -1, 64)
	priceArr["high"] = strconv.FormatFloat(priceData.High, 'f', -1, 64)
	priceArr["low"] = strconv.FormatFloat(priceData.Low, 'f', -1, 64)
	priceArr["amount"] = strconv.FormatFloat(priceData.Amount, 'f', -1, 64)
	priceArr["third_update_time"] = strconv.FormatInt(priceData.ID, 10)
	if strings.ToLower(apiSymbol) == "shibusdt" {
		priceArr["open"] = fmt.Sprintf("%.8f", priceData.Open)
		priceArr["close"] = fmt.Sprintf("%.8f", priceData.Close)
	}
	return priceArr, nil
}
